<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="s"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<s:admin pageName="img_map">
<jsp:attribute name="headPart">
	<script src="<c:url value="/resources/solidtrust/list.js" />"></script>
	<script>
		$.get('brands', function(array){
			var list1 = new Solid.List($('.image_brand'), array[0], function(id, text, btn){
				var btn = $('.standard_brand').find('.btn-danger');
				if(btn.size() > 0){
					var b = btn.get(0);
					var id = b.id.substring(b.id.indexOf('_') + 1);
					$.post('mapImageBrand', {
						standardBrandId: id,
						imageBrand: text
					},function(count){
						console.log(count);
						list2.remove(id);
						list3.add({id: id, text: text1});
					})
				}
			})
			var list2 = new Solid.List($('.standard_brand'), array[1], function(id, text, btn){
				$('.standard_brand').find('.btn-danger').removeClass('btn-danger');
				if($(btn).hasClass('btn-default')){
					$(btn).addClass('btn-danger').removeClass('btn-default');
				}else{
					$(btn).addClass('btn-default');
				}
			})
			var list3 = new Solid.List($('.mapped_brand'), array[2], function(brandId, text, btn){
				$('.mapped_brand').find('.btn-danger').removeClass('btn-danger');
				if($(btn).hasClass('btn-default')){
					$(btn).addClass('btn-danger').removeClass('btn-default');
				}else{
					$(btn).addClass('btn-default');
				}
				$.get('models?brandId=' + brandId, function(array1){
					var list4 = new Solid.List($('.image_model'), array1[0], function(id, text, btn){
						var btn = $('.standard_model').find('.btn-danger');
						if(btn.size() > 0){
							var b = btn.get(0);
							var modelId = b.id.substring(b.id.indexOf('_') + 1);
							var text1 = b.value;
							$.post('mapImageModel', {
								standardModelId: modelId,
								standardBrandId: brandId,
								imageModel: text
							},function(count){
								console.log(count);
								list5.remove(modelId);
								list6.add({id: id, text: text1});
							})
						}
					})
					var list5 = new Solid.List($('.standard_model'), array1[1], function(id, text, btn){
						$('.standard_model').find('.btn-danger').removeClass('btn-danger');
						if($(btn).hasClass('btn-default')){
							$(btn).addClass('btn-danger').removeClass('btn-default');
						}else{
							$(btn).addClass('btn-default');
						}
					})
					var list6 = new Solid.List($('.mapped_model'), array1[2], function(id, text, btn){
						debugger;
					})
				})
			})
		})
		
		
		
	</script>
</jsp:attribute>
<jsp:body>
<div class="row main">
	<h4 class="page-header">Image Car Mapping</h4>
	<div>
		<h5>Brand</h5>
		<div class="col-md-4 standard_brand">
		</div>
		<div class="col-md-4 image_brand">
		</div>
		<div class="col-md-4 mapped_brand">
		</div>
	</div>
	
	<div>
		<h5>Model</h5>
		<div class="col-md-4 standard_model">
		</div>
		<div class="col-md-4 image_model">
		</div>
		<div class="col-md-4 mapped_model">
		</div>
	</div>
</div>
</jsp:body>
</s:admin>
